import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../enum/token.dart';
class CommonUtils{
  //存入token
  static Future<bool> saveToken(Token tokenType,String token) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    print("${tokenType.toString()}已存入");
    return prefs.setString(tokenType.toString(), token);
  }
  //获取token
  static Future<String> getToken(Token tokenType) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(tokenType.toString()) ?? '';
  }
  //清除token
  static Future<bool> clearToken(Token tokenType) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.remove(tokenType.toString());
  }

  //封装toast弹窗
  static void showToast(String msg) {
    Get.snackbar(
        "提示！",
        msg,
        snackPosition: SnackPosition.TOP,
        icon: Icon(Icons.error),
        mainButton:
        TextButton(onPressed: (){
          Get.back();
        }, child: Text("确定"))
    );
  }

  static void showBotToast(String msg){
    BotToast.showText(
      text:msg,
      //设置位置
      align:  Alignment.topCenter,
    );
  }
}